<template>
  <div class="dashboard-container">
    <el-button type="normal" size="small" @click="dialogVisible = true">新建目录</el-button>

    <el-dialog title="新建目录" :visible.sync="dialogVisible" width="40%">
      <el-form ref="form" :rules="rules" :model="form" label-width="120px">
         <el-form-item label="目录名称:"  prop="directoryName">
           <el-input v-model="form.directoryName"/>
         </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="submit()">Confirm</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import add from '@/api/hmmm/directorys'
export default {
  name: 'DirectorysAdd',
  data() {
    return {
      dialogVisible: false,
      form: {
        subjectID: 1,
        directoryName: ''
      },
      rules: {
          dirName: [
            { required: true, message: 'Please input dir name', trigger: 'blur' },
            { min: 3, max: 25, message: 'Length should be 3 to 25', trigger: 'blur' }
          ]
      }
    }
  },
  methods: {
    submit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          add(this.dirName).then(data => {
            console.log(data)
          })
        } else {
          return false
        }
      })
      dialogVisible = false
    }
  }
}
</script>

<style scoped>
</style>
